package com.suray.type;

/**
 * 故障等级
 * 等级越小故障越严重
 * 3级以上(包括3级)为故障
 * 3级以下为警告
 */
public enum ErrorLevel {
    ERROR_LEVEL_1(1,"1级故障"),
    ERROR_LEVEL_2(2,"2级故障"),
    ERROR_LEVEL_3(3,"3级故障"),
    ERROR_LEVEL_4(4,"4级故障"),
    ERROR_LEVEL_5(5,"5级故障"),
    ERROR_LEVEL_WCS(0xFF,"WCS自定义"),
    ERROR_LEVEL_SPECIAL(0x100,"特殊故障"),
    NON_ERROR(0xFFFF, "无故障"),
    ;

    int value;
    String des;
    ErrorLevel(int value, String des) {
        this.value = value;
        this.des = des;
    }

    public int getValue() {
        if (this.equals(ERROR_LEVEL_WCS)) {
            //WCS故障等级等同于3级故障
            return ERROR_LEVEL_3.value;
        }

        return value;
    }

    public boolean checkLevel(ErrorLevel errorLevel) {
        return this.getValue() < errorLevel.getValue();
    }

    public static ErrorLevel parseLevel(int value) {
        for (ErrorLevel errorLevel : ErrorLevel.values()) {
            if (errorLevel.getValue() == value) {
                return errorLevel;
            }
        }

        return null;
    }

    @Override
    public String toString() {
        return des;
    }
}
